package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.DeviceAlarmRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【device_alarm_record】的数据库操作Mapper
* @createDate 2023-07-04 13:56:42
* @Entity com.example.military.entity.AlarmRecord
*/
@Mapper
public interface DeviceAlarmRecordMapper extends BaseMapper<DeviceAlarmRecord> {

    @Select("select * from device_alarm_record order by id desc")
    @Select("<script>select * from device_alarm_record " +
            " <where> " +
            " <if test=\"solve != null and solve != ''\">and solve like concat('%',#{solve},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and time &lt;= #{endTime} </if> " +
            " <if test=\"type != null and type != ''\">and type like concat('%',#{type},'%') </if> " +
            " </where> " +
            "order by id desc</script>")
    List<DeviceAlarmRecord> get(@Param("beginTime") String beginTime, @Param("endTime")String endTime,
                                @Param("solve") String solve, @Param("type")String type);

    @Insert("insert into device_alarm_record(alarm_level,time,sn,address,note,solve,handle,type,phone,handle_message) " +
            "values (#{alarmLevel},#{time},#{sn},#{address},#{note},#{solve},#{handle},#{type},#{phone},#{handleMessage})")
    int add(DeviceAlarmRecord record);

    @Delete("<script>delete from device_alarm_record where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteAlarmRecord(@Param("ids") Integer[] ids);

    @Update("update device_alarm_record set solve='已处理',handle=#{handle},handle_message=#{handleMessage} where id = #{id}")
    int handle(@Param("id")Integer id, @Param("handle")String handle, @Param("handleMessage")String handleMessage);

    @Select("select * from device_alarm_record where id=#{id}")
    DeviceAlarmRecord getById(@Param("id") Integer id);

    @Select("select * from device_alarm_record where alarm_level like concat('%',#{alarmLevel},'%') order by id desc")
    List<DeviceAlarmRecord> getByLevel(@Param("alarmLevel") String alarmLevel);

    @Select("select * from device_alarm_record where time between #{beginTime} and #{endTime} order by id desc")
    List<DeviceAlarmRecord> getByTime(@Param("beginTime") String beginTime, @Param("endTime")String endTime);

}




